﻿@model AexoManager.Models.PartesViewModel
@{
    ViewBag.Title = "PartesDetalle";
    Layout = "~/Views/Shared/_Template.cshtml";
}

@section ClientScripts {
    <script type='text/javascript'>
        $(function () {
            $("#FechaDesde").datepicker({ dateFormat: "dd/mm/yy" });
            $("#FechaHasta").datepicker({ dateFormat: "dd/mm/yy" });

            $("#btnSubmit").click(function () {
                $("#formPrincipal").submit();
            });

            $('#gdCosto').dataTable({
                "sDom": "<'row'<'col-sm-12'T><'col-sm-12'f>r>t<'row'<'col-sm-12'i><'col-sm-12'p>>",
                "bProcessing": false,
                "bServerSide": false,
                "bAutoWidth": false,
                "oTableTools": {
                    "sRowSelect": "single",
                    "aButtons": [
                    ]
                }
            });

            $('.dataTables_filter input').addClass('form-control').attr('style', 'display:none');
            $('.dataTables_length select').addClass('form-control');

            $("#dialog-costo").dialog({
                autoOpen: false,
                height: 350,
                width: 500,
                modal: true
            });

            $("#btnAgregar").click(function () {
                $("#IdCosto").val("");
                $("#FechaDesde").val("");
                $("#FechaHasta").val("");
                $("#Importe").val("");
                $("#dialog-costo").dialog("open");
            });
            $("#btnModificar").click(function () {
                $("#IdCosto").val($("#gdCosto .active").children("td:eq(0)").text());
                $("#FechaDesde").val($("#gdCosto .active").children("td:eq(1)").text());
                $("#FechaHasta").val($("#gdCosto .active").children("td:eq(2)").text());
                $("#Importe").val($("#gdCosto .active").children("td:eq(3)").text());
                $("#dialog-costo").dialog("open");
            });

            $("#btnCerrar").click(function () {
                $("#dialog-costo").dialog("close");
            });

            $("#btnAceptar").click(function () {

                $.ajax({
                    type: "POST",
                    url: '@Url.Action("SaveCosto", "Partes")',
                    data: { 'fechaDesde': $("#FechaDesde").val(), 'fechaHasta': $("#FechaHasta").val(), 'importe': $("#Importe").val() },
                    dataType: 'json',
                    cache: false,
                    success: function (data) {
                        alert("Se guardo correctamente");
                        $("#dialog-costo").dialog("close");
                    },
                    error: function () { alert("Connection Failed. Please Try Again"); }
                });


            });

        });

        function graboCosto() {
            alert("Se guardo correctamente.");
        }
    </script>
}
<div id="page-content">
    <div id='wrap'>
        <div id="page-heading">
            <ol class="breadcrumb">
                <li class='active'><a href="index.php">Produccion</a></li>
                <li class='active'><a href="index.php">Estadisticas Registro</a></li>
            </ol>

            <h1>Partes</h1>
        </div>
        <div class="container">
            <div class="panel panel-midnightblue">
                <div class="panel-heading">
                    <h4>Parte</h4>
                </div>
                <div class="panel-body collapse in">
                    @using (Html.BeginForm("Guardar", "Partes", FormMethod.Post, new { @id = "formPrincipal", @class = "form-horizontal row-border" }))
                    {
                        <div class="form-group">
                            <label class="col-sm-3 control-label">Codigo</label>
                            <div class="col-sm-6">
                                @Html.TextBoxFor(model => model.Codigo, new { @class = "form-control" })
                                @Html.HiddenFor(model => model.IdParte)
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">Descripcion</label>
                            <div class="col-sm-6">
                                @Html.TextBoxFor(model => model.Descripcion, new { @class = "form-control" })
                            </div>
                        </div>
                        <!--table-->
                        if (ViewBag.CostosDeParte != null)
                        {
                            <table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered datatables" id="gdCosto">
                                <thead>
                                    <tr>
                                        <th width="30%" style="padding:5px">IdCosto</th>
                                        <th width="30%" style="padding:5px">Fecha Desde</th>
                                        <th width="20%" style="padding:5px">Fecha Hasta</th>
                                        <th width="18%" style="padding:5px">Costo</th>
                                    </tr>
                                </thead>
                                <tbody>

                                    @foreach (var item in ViewBag.CostosDeParte)
                                    {
                                        <tr>
                                            <td style="padding:5px">@item.IdCosto</td>
                                            <td style="padding:5px">@item.FechaDesde.ToString("dd/MM/yyyy")</td>
                                            <td style="padding:5px">@if (item.FechaHasta != null) { item.FechaHasta.ToString("dd/MM/yyyy"); }</td>
                                            <td style="padding:5px">@item.Importe</td>
                                        </tr>
                                    }

                                </tbody>
                            </table>
                            <!--end table-->
                        }
                        if (Model != null)
                        {
                            <input type="button" class="btn-primary btn" id="btnAgregar" value="Agregar Costo" />
                            <input type="button" class="btn-primary btn" id="btnModificar" value="Modificar Costo" />
                        
                        }
                    }

                    <div class="panel-footer">
                        <div class="row">
                            <div class="col-sm-6 col-sm-offset-3">
                                <div class="btn-toolbar">
                                    <button id="btnSubmit" class="btn-primary btn">Submit</button>
                                    <button class="btn-default btn">Cancel</button>
                                </div>
                            </div>
                        </div>
                    </div>

                </div>
                @*using (Ajax.BeginForm("SaveCosto", "Partes", new AjaxOptions(){ HttpMethod = "POST", OnComplete = "GraboCosto"}))
                    {*@
                <div id="dialog-costo">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">Fecha desde</label>
                        <div class="col-sm-8" style="margin-bottom:15px">
                            @Html.TextBoxFor(model => model.FechaDesde, new { @class = "form-control" })
                            @Html.HiddenFor(model => model.IdCosto)
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">Fecha hasta</label>
                        <div class="col-sm-8" style="margin-bottom:15px">
                            @Html.TextBoxFor(model => model.FechaHasta, new { @class = "form-control" })
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">Importe</label>
                        <div class="col-sm-8" style="margin-bottom:15px">
                            @Html.TextBoxFor(model => model.Importe, new { @class = "form-control" })
                        </div>
                    </div>

                    <div class="panel-footer">
                        <div class="row">
                            <div class="col-sm-6 col-sm-offset-3">
                                <div class="btn-toolbar">
                                    <input type="submit" id="btnAceptar" class="btn-primary btn" value="Aceptar" />
                                    <button id="btnCerrar" class="btn-default btn">Cancel</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                @*}*@
            </div>
        </div>
    </div> <!--wrap -->
</div> <!-- page-content -->